﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.fminutes.vinciIsometric.core {
    import flash.geom.*;

    public class IsoUtils {

        public static const Y_CORRECT:Number = (Math.cos((-(Math.PI) / 6)) * Math.SQRT2);

        public static function isoToScreen(_arg1:Vector3D):Point{
            var _local2:Number = (_arg1.x - _arg1.z);
            var _local3:Number = ((_arg1.y * Y_CORRECT) + ((_arg1.x + _arg1.z) * 0.5));
            return (new Point(_local2, _local3));
        }
        public static function screenToIso(_arg1:Point):Vector3D{
            var _local2:Number = (_arg1.y + (_arg1.x * 0.5));
            var _local3:Number = 0;
            var _local4:Number = (_arg1.y - (_arg1.x * 0.5));
            return (new Vector3D(_local2, _local3, _local4));
        }
        public static function screenToIsoB(_arg1:Point, _arg2:Vector3D, _arg3:Boolean=true):Vector3D{
            var _local4:Number;
            var _local5:Number;
            var _local6:Number;
            var _local7:Number;
            var _local8:Number;
            _arg2 = _arg2.clone();
            if (_arg3){
                _local7 = _arg1.y;
                _arg2.y = 0;
                _arg2.x = (screenToIso(_arg1).x + (_arg2.z - screenToIso(_arg1).z));
                _local8 = isoToScreen(_arg2).y;
                _local4 = _arg2.x;
                _local5 = ((_local7 - _local8) / Y_CORRECT);
                _local6 = _arg2.z;
            } else {
                _local7 = _arg1.y;
                _arg2.y = 0;
                _arg2.z = (screenToIso(_arg1).z + (_arg2.x - screenToIso(_arg1).x));
                _local8 = isoToScreen(_arg2).y;
                _local4 = _arg2.x;
                _local5 = ((_local7 - _local8) / Y_CORRECT);
                _local6 = _arg2.z;
            };
            return (new Vector3D(_local4, _local5, _local6));
        }
        public static function toDirection(_arg1:int):int{
            return ((Math.round((_arg1 / 45)) * 45));
        }
        public static function targetDirection(_arg1:Vector3D, _arg2:Vector3D):int{
            var _local3:Number = (_arg2.x - _arg1.x);
            var _local4:Number = (_arg2.z - _arg1.z);
            var _local5:Number = ((Math.atan2(_local4, _local3) * 180) / Math.PI);
            _local5 = (_local5 - 90);
            _local5 = ((360 + _local5) % 360);
            return (IsoUtils.toDirection(_local5));
        }
        public static function toDouble(_arg1:int, _arg2:int):int{
            var _local3:int = (Math.ceil((_arg1 / _arg2)) * _arg2);
            return (_local3);
        }

    }
}//package com.fminutes.vinciIsometric.core 
